package com.macroye.controller;

import com.macroye.result.Result;
import com.macroye.utils.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/allCommon")
public class AllCommonController {

    @Autowired
    HttpServletRequest request;

    @Autowired
    RedisTemplate<String,Object> redisTemplate;

    /**
     * 登出
     */
    @PostMapping("/layout")
    public Result layout(){
        //获取token
        String token = request.getHeader(JwtUtils.TOKEN);
        //解析token
        String userKey = JwtUtils.getUserKey(token);
        redisTemplate.delete(JwtUtils.LOGIN_TOKEN_KEY+userKey);
        return Result.success();
    }


}
